import Vue from 'vue';
import Component from './v-dialog.vue';
const DialogConstructor = Vue.extend(Component);

const dialog = (options) => {
  return new Promise((resolve, reject) => {
    if (Vue.prototype.$isServer) return
    options = options || {}
    const instance = new DialogConstructor({
      propsData: options
    })

    instance.vm = instance.$mount();
    document.body.appendChild(instance.vm.$el)

    instance.boxshow = true;

    instance.$on("enter", () => {
      resolve();
    })

    instance.$on("esc", () => {
      reject();
    })
  })
}

Vue.prototype.$vDialog = dialog;

export default dialog;
